# coding: utf-8
import sys
from threading import Thread

import Function
import SimpleWS
from CFtdcMdSpi import ConnectMd_CFFEX, ConnectMd_SHFE, ConnectMd_INE, ConnectMd_GFEX, ConnectMd_DCE, ConnectMd_CZCE

from CTraderSpi import ConnectTrader
from LogUtil import timePrintLog

if 'linux' in sys.platform:
    from CTP_API.linux import thosttraderapi as tdapi
if 'win' in sys.platform:
    from CTP_API.window import thosttraderapi as tdapi

if __name__ == '__main__':
    try:
        # CTP 版本
        timePrintLog(f'CTP API Version:{tdapi.CThostFtdcTraderApi_GetApiVersion()}')

        # 加载合约信息
        Function.instrument_info_all = Function.load()

        ws = Thread(target=SimpleWS.startWbSocket)
        ws.start()

        md1 = Thread(target=ConnectMd_CFFEX)
        md1.start()

        md2 = Thread(target=ConnectMd_CZCE)
        md2.start()

        md3 = Thread(target=ConnectMd_DCE)
        md3.start()

        md4 = Thread(target=ConnectMd_GFEX)
        md4.start()

        md5 = Thread(target=ConnectMd_INE)
        md5.start()

        md6 = Thread(target=ConnectMd_SHFE)
        md6.start()

        td = Thread(target=ConnectTrader)
        td.start()


    except Exception as e:
        print(e.__str__())
